/*
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package jchess;

/**
 * Class to represent a chessboard square
 */
public class Square {

    private int pozX; // 0-7, becouse 8 squares for row/column
    private int pozY; // 0-7, becouse 8 squares for row/column
    public Piece piece = null;//object Piece on square (and extending Piecie)

    Square(int pozX, int pozY, Piece piece) {
        this.pozX = pozX;
        this.pozY = pozY;
        this.piece = piece;
    }/*--endOf-Square--*/


    Square(Square square) {
        this.pozX = square.pozX;
        this.pozY = square.pozY;
        this.piece = square.piece;
    }

    public Square clone(Square square) {
        return new Square(square);
    }

    void setPiece(Piece piece) {
        this.piece = piece;
        this.piece.square = this;
    }

    /**
     * @return the piece
     */
    public Piece getPiece() {
        return piece;
    }

    /**
     * @return the pozX
     */
    public int getPozX() {
        return pozX;
    }

    /**
     * @return the pozY
     */
    public int getPozY() {
        return pozY;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof Square) {
            Square outraCasa = (Square) o;
            return this.pozX == outraCasa.pozX && this.pozY == outraCasa.pozY;
        }
        return false;
    }

    // metodo para retornar a representacao literal de uma casa (ex.: a8, c6) em vez de indices de matriz
    @Override
    public String toString() {
        int[] array = {7, 6, 5, 4, 3, 2, 1, 0};
        int tempY = array[pozY];
        return Character.toString((char) (pozX + 97)) + Integer.toString(tempY + 1);
    }
}
